package net.lab1024.sa.admin.module.business.roland.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.lab1024.sa.admin.module.business.roland.domain.form.RolandOrderForm;
import net.lab1024.sa.admin.module.business.roland.domain.form.RolandRegisterForm;
import net.lab1024.sa.admin.module.business.roland.domain.form.RolandTicketQueryForm;
import net.lab1024.sa.admin.module.business.roland.domain.vo.PerformanceTypeSelectVO;
import net.lab1024.sa.admin.module.business.roland.domain.vo.RolandMyTicketVO;
import net.lab1024.sa.admin.module.business.roland.domain.vo.RolandRegisterVO;
import net.lab1024.sa.admin.module.business.roland.domain.vo.RolandSeatFrontVO;
import net.lab1024.sa.admin.module.business.roland.service.RolandCustomerService;
import net.lab1024.sa.admin.module.business.roland.service.RolandOrderService;
import net.lab1024.sa.admin.module.business.roland.service.RolandPerformanceTypeService;
import net.lab1024.sa.admin.module.business.roland.service.RolandSeaService;
import net.lab1024.sa.common.common.domain.ResponseDTO;
import net.lab1024.sa.common.module.support.config.ConfigKeyEnum;
import net.lab1024.sa.common.module.support.config.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.math.BigDecimal;
import java.util.List;

/**
 * @author Dragon
 **/
@RestController
@Api(tags = "")
public class HomeController {

    @Autowired
    private RolandCustomerService rolandCustomerService;
    @Autowired
    private RolandOrderService rolandOrderService;
    @Autowired
    private RolandPerformanceTypeService rolandPerformanceTypeService;
    @Autowired
    private ConfigService configService;
    @Autowired
    private RolandSeaService rolandSeaService;

    @ApiOperation("是否开启售票")
    @GetMapping("/home/isOpening")
    public ResponseDTO<String> isOpening() {
        String configValue = configService.getConfigValue(ConfigKeyEnum.IS_OPENING);

        boolean isOpening = false;
        if (configValue != null) {
            isOpening = Boolean.parseBoolean(configValue);
        }

        String msg = null;
        if (!isOpening) {
            msg = "售票暂未开启，请等待";
        }

        return ResponseDTO.ok(msg);
    }

    @ApiOperation("表演节目下拉")
    @GetMapping("/home/performanceSelector")
    public ResponseDTO<List<PerformanceTypeSelectVO>> queryAll() {
        return rolandPerformanceTypeService.queryAll();
    }


    @ApiOperation("下单前置操作")
    @PostMapping("/home/register")
    public ResponseDTO<RolandRegisterVO> register(@RequestBody @Valid RolandRegisterForm param) {
        return rolandCustomerService.register(param);
    }


    @ApiOperation("座位列表")
    @GetMapping("/home/seats")
    public ResponseDTO<List<RolandSeatFrontVO>> seats() {
        return rolandSeaService.seats();
    }

    @ApiOperation("下单")
    @PostMapping("/home/order")
    public ResponseDTO<BigDecimal> order(@RequestBody @Valid RolandOrderForm addForm) {
        return rolandOrderService.order(addForm);
    }

    @ApiOperation("已购买的票")
    @PostMapping("/home/ticket")
    public ResponseDTO<List<RolandMyTicketVO>> ticket(@RequestBody @Valid RolandTicketQueryForm param) {
        return rolandOrderService.ticket(param);
    }

}
